const { mysql } = require('../qcloud')

module.exports = async (ctx) => {
    const { openid } = ctx.request.query

    try {
        // 查询是否有改用户的信息
        const res = await mysql('cSessionInfo')
            .where('open_id', openid)
            .select('open_id')
            .first()
        if (res) {
            var open_id = res.open_id
        } else {
            var open_id = null;
        }
        console.log("查询到的openid", open_id)

        ctx.state.data = {
            code: 0,
            msg: 'success',
            open_id: open_id
        }
        console.log("执行成功")
    } catch (e) {
        ctx.state = {
            code: -1,
            data: {
                msg: "查询失败" + e.sqlMessage
            }
        }
        console.log("执行错误", e)
    }

}